# ==== memory.py ====
class Memory:
    def __init__(self):
        self.inst_mem = [0] * 1024
        self.data_mem = [0] * 1024

    def load_program(self, program):
        for i, instr in enumerate(program):
            if i < len(self.inst_mem):
                self.inst_mem[i] = instr

    def read_inst(self, pc):
        if 0 <= pc < len(self.inst_mem):
            return self.inst_mem[pc]
        return 0

    def read_data(self, addr):
        if 0 <= addr < len(self.data_mem):
            return self.data_mem[addr]
        return 0

    def write_data(self, addr, data):
        if 0 <= addr < len(self.data_mem):
            self.data_mem[addr] = data